package cn.tedu.csmall.stock.webapi.quartz.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

// 当前类作用是定义交换机\路由Key\队列的对象,和绑定关系
// 路由模式下,只有配置了这些信息,才能正常运行
@Configuration
public class RabbitMQConfig {

    // 业务中需要使用到的各种名称都要定义常量,防止拼写错误
    public static final String STOCK_EX="stock_ex";
    public static final String STOCK_ROUT="stock_rout";
    public static final String STOCK_QUEUE="stock_queue";

    // 交换机和队列对象是实例对象,保存到Spring容器
    @Bean
    public DirectExchange stockDirectExchange(){
        return new DirectExchange(STOCK_EX);
    }
    @Bean
    public Queue stockQueue(){
        return new Queue(STOCK_QUEUE);
    }

    // 路由Key是表示关系的对象,需要绑定相关的对象
    @Bean
    public Binding stockBinding(){
        return BindingBuilder.bind(stockQueue()).
                to(stockDirectExchange()).with(STOCK_ROUT);
    }


}
